package com.cmc.cloud.cmclink.doc.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cmc.cloud.cmclink.doc.entity.DgProhibitedDO;
import com.cmc.cloud.cmclink.doc.entity.DgProhibitedWithSubDO;
import com.cmc.cloud.cmclink.doc.vo.special.dgprohibitedvo.DgProhibitedExcelReqVO;
import com.cmc.cloud.cmclink.doc.vo.special.dgprohibitedvo.DgProhibitedPageReqVO;
import com.cmes.framework.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 危险品禁接清单 Mapper
 *
 * @author 集运管理员
 */
@Mapper
public interface DgProhibitedMapper extends BaseMapperX<DgProhibitedDO> {
    /**
     * 危险品禁接清单查询
     *
     * @param page
     * @param queryWrapper
     * @return
     */
    IPage<DgProhibitedDO> selectPage(IPage<DgProhibitedDO> page,
                                     LambdaQueryWrapper<DgProhibitedPageReqVO> queryWrapper);

    /**
     * 危险品禁接清单主子查询
     *
     * @param excelReqVO
     * @return
     */
    @Select("<script>\n" + "SELECT a.id,a.list_type,a.code_type,a.code_value,a.port_type,a.imo_class,\n"
            + "a.cntr_types,a.remark,a.start_date,a.end_date,\n"
            + "b.id as sub_id,b.subsidiary_risk,b.un_no,b.flash_point,b.packing_group,b.remark as sub_remark\n"
            + "from doc_dg_prohibited a left join doc_dg_prohibited_item b on a.id = b.main_id\n"
            + "where a.deleted = 0 and b.deleted = 0\n" + "    <if test='req.listType != null and req.listType != \"\"'>\n"
            + "        and a.list_type =#{req.listType}\n" + "    </if>\n"
            + "    <if test='req.codeType != null and req.codeType != \"\"'>\n"
            + "        and a.code_type =#{req.codeType}\n" + "    </if>\n"
            + "    <if test='req.codeValue != null and req.codeValue != \"\"'>\n"
            + "        and a.code_value =#{req.codeValue}\n" + "    </if>\n" + "</script>")
    @Results(id = "selectAllWithSub", value = {@Result(column = "id", property = "id"),
            @Result(column = "list_type", property = "listType"), @Result(column = "code_type", property = "codeType"),
            @Result(column = "code_value", property = "codeValue"), @Result(column = "port_type", property = "portType"),
            @Result(column = "imo_class", property = "imoClass"), @Result(column = "cntr_types", property = "cntrTypes"),
            @Result(column = "remark", property = "remark"), @Result(column = "start_date", property = "startDate"),
            @Result(column = "end_date", property = "endDate"), @Result(column = "sub_id", property = "subId"),
            @Result(column = "subsidiary_risk", property = "subsidiaryRisk"), @Result(column = "un_no", property = "unNo"),
            @Result(column = "flash_point", property = "flashPoint"),
            @Result(column = "packing_group", property = "packingGroup"),
            @Result(column = "sub_remark", property = "subRemark")})
    List<DgProhibitedWithSubDO> selectAllWithSubList(@Param("req") DgProhibitedExcelReqVO excelReqVO);
}
